package cn.keniykey.mc.viewlibrary;

import java.util.logging.Logger;

import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;

import cn.keniykey.mc.viewlibrary.container.ContainerPlayerListener;

public final class ViewLibraryMain extends JavaPlugin{
	
	private static ViewLibraryMain plugin;
	
	@Override
	public void onLoad() {
		plugin = this;
	}
	public static ViewLibraryMain getPlugin() {
		return plugin;
	}
	
	@Override
	public void onEnable() {
		final Logger logger = this.getLogger();
		logger.info("插件正在启用中，版本为：" + this.getDescription().getVersion());
		try {
			this.getServer().getPluginManager().registerEvents(new ContainerPlayerListener(), this);
		}catch(Exception ex) {
			ex.printStackTrace();
			logger.warning("初始化Container必须前置Channel和/或Packet失败");
			this.getServer().getPluginManager().disablePlugin(this);
			return;
		}
		logger.info("初始化Container必须前置Channel和Packet成功");
		logger.info("插件启用完成");
	}
	
	@Override
	public void onDisable() {
		final Logger logger = this.getLogger();
		logger.info("插件正在关闭中，版本为：" + this.getDescription().getVersion());
		this.getServer().getScheduler().cancelTasks(this);
		HandlerList.unregisterAll(this);
		logger.info("插件关闭完成");
	}
	
}